<template>
  <div>
    功能：
    <table>
      <tr>
        <td v-for="i in typelist">
          <button @click="change(i.id)" :class="i.id==typeid?'active':''">{{ i.name }}</button>
        </td>
      </tr>
    </table>

    展示：
    <table>
      <tr>
        <td>
          <button @click="order">排序</button>
        </td>
        <td>开始时间</td>
        <td>结束时间</td>
        <td>价格</td>
      </tr>
      <tr v-for="i in recorlist">
        <td>{{ i.id }}</td>
        <td>{{ i.stime }}</td>
        <td>{{ i.etime }}</td>
        <td>{{ i.money }}</td>
        <td><a :href="''">详情</a></td>
      </tr>
    </table>
  </div>
</template>

<script>
export default {
  name: "effect1",
  data() {
    return {
      typelist: [],
      recorlist: [],
      typeid: 0,
      sort: 'asc'
    }
  },

  methods: {
    gettypelist() {
      this.axios.get('ypM').then(res => {
        this.typelist = res.data.list
      })
    },
    getrlist() {
      this.axios.get('recorM?typeid=' + this.typeid + '&sort=' + this.sort).then(res => {
        this.recorlist = res.data.list
      })
    },
    change(typeid) {
      this.typeid = typeid
      this.getrlist()
    },
    order() {
      if (this.sort == 'asc') {
        this.sort = 'desc'
      } else {
        this.sort = 'asc'
      }
      this.getrlist()
    }
  },

  mounted() {
    this.gettypelist()
    this.getrlist()
  }
}
</script>

<style scoped>
.active {
  background-color: cyan;
}

</style>
